package com.song.tradition.page.components

import android.widget.Toast
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.background

import androidx.compose.foundation.clickable

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ExitToApp
import androidx.compose.material.icons.outlined.Favorite
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.DrawerState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
import com.song.tradition.R
import com.song.tradition.ui.theme.customBgColor
import com.song.tradition.ui.theme.customCardBgColor
import com.song.tradition.ui.theme.customTextColor
import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DrawerScreen(
    navController: NavHostController,
    drawerState: DrawerState
) {
    val scope = rememberCoroutineScope()
    val context = LocalContext.current


    Surface(
        modifier = Modifier
            .fillMaxHeight()
            .width(300.dp),
        shape = RoundedCornerShape(topEnd = 30.dp)
    ) {

        Column(
            modifier = Modifier
                .fillMaxSize()
                .background(customBgColor)
                .padding(8.dp)
        ) {

            Spacer(modifier = Modifier.height(32.dp))

            Row(
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(horizontal = 8.dp),
                verticalAlignment = Alignment.CenterVertically
            ) {

                Card(
                    modifier = Modifier.size(64.dp),
                    shape = CircleShape,
                    elevation = CardDefaults.cardElevation(
                        defaultElevation = 2.dp,
                        pressedElevation = 3.dp,
                        hoveredElevation = 0.dp
                    ),
                    border = BorderStroke(width = 1.dp, color = customCardBgColor)
                ) {
                    Image(
                        painterResource(id = R.drawable.avatar),
                        contentDescription = "",
                        Modifier
                            .size(64.dp)
                            .clip(CircleShape)
                    )
                }
                Spacer(modifier = Modifier.width(16.dp))
                Column(modifier = Modifier.weight(1f)) {

                    Text(text = "Song", fontSize = 22.sp, fontWeight = FontWeight.Bold)
                    Spacer(modifier = Modifier.height(8.dp))
                    Text(text = "早上好！")
                }


            }

            Spacer(modifier = Modifier.height(32.dp))

            Column(
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(8.dp)
            ) {

                Card(
                    modifier = Modifier
                        .height(48.dp)
                        .fillMaxWidth()
                        .clickable {

                            scope.launch {
                                drawerState.close()
                            }
                            navController.navigate(ScreenRoute.OriginScreen.route)
                        },

                    shape = RoundedCornerShape(10.dp),
                    colors = CardDefaults.cardColors(
                        containerColor = customCardBgColor, contentColor = customTextColor
                    ),
                    elevation = CardDefaults.elevatedCardElevation(2.dp)
                )
                {
                    Row(
                        modifier = Modifier
                            .fillMaxSize()
                            .padding(horizontal = 8.dp),
                        verticalAlignment = Alignment.CenterVertically
                    ) {
                        Icon(
                            painterResource(id = R.drawable.baseline_library_books_24),
                            contentDescription = ""
                        )

                        Spacer(modifier = Modifier.width(16.dp))

                        Text(text = "中医起源")
                    }
                }
                Spacer(modifier = Modifier.height(8.dp))

                Card(
                    modifier = Modifier
                        .height(48.dp)
                        .fillMaxWidth()
                        .clickable {
                            scope.launch {
                                drawerState.close()
                            }
                            navController.navigate(ScreenRoute.AboutScreen.route)

                        },

                    shape = RoundedCornerShape(10.dp),
                    colors = CardDefaults.cardColors(
                        containerColor = customCardBgColor, contentColor = customTextColor
                    ),
                    elevation = CardDefaults.elevatedCardElevation(2.dp)
                )
                {
                    Row(
                        modifier = Modifier
                            .fillMaxSize()
                            .padding(horizontal = 8.dp),
                        verticalAlignment = Alignment.CenterVertically
                    ) {
                        Icon(imageVector = Icons.Outlined.ExitToApp, contentDescription = "")

                        Spacer(modifier = Modifier.width(16.dp))
                        Text(text = "关于应用")
                    }
                }
                Spacer(modifier = Modifier.height(8.dp))
                Card(
                    modifier = Modifier
                        .height(48.dp)
                        .fillMaxWidth()
                        .clickable {
                            Toast
                                .makeText(context, "稍等，小编正在开发呢", Toast.LENGTH_LONG)
                                .show()
                        },

                    shape = RoundedCornerShape(10.dp),
                    colors = CardDefaults.cardColors(
                        containerColor = customCardBgColor, contentColor = customTextColor
                    ),
                    elevation = CardDefaults.elevatedCardElevation(5.dp)
                )
                {
                    Row(
                        modifier = Modifier
                            .fillMaxSize()
                            .padding(horizontal = 8.dp),
                        verticalAlignment = Alignment.CenterVertically
                    ) {
                        Icon(imageVector = Icons.Outlined.Settings, contentDescription = "")

                        Spacer(modifier = Modifier.width(16.dp))

                        Text(text = "设置")
                    }
                }
                Spacer(modifier = Modifier.height(8.dp))
                Card(
                    modifier = Modifier
                        .height(48.dp)
                        .fillMaxWidth()
                        .clickable {
                            Toast
                                .makeText(context, "稍等，小编正在开发呢", Toast.LENGTH_LONG)
                                .show()
                        },

                    shape = RoundedCornerShape(10.dp),
                    colors = CardDefaults.cardColors(
                        containerColor = customCardBgColor, contentColor = customTextColor
                    ),
                    elevation = CardDefaults.elevatedCardElevation(5.dp)
                )
                {
                    Row(
                        modifier = Modifier
                            .fillMaxSize()
                            .padding(horizontal = 8.dp),
                        verticalAlignment = Alignment.CenterVertically
                    ) {
                        Icon(imageVector = Icons.Outlined.Favorite, contentDescription = "")

                        Spacer(modifier = Modifier.width(16.dp))

                        Text(text = "我的收藏")
                    }
                }


                Spacer(modifier = Modifier.height(8.dp))

            }
        }
    }
}


